<template>
  <div class="wrap-left-form">
    <el-form
      class="custom-form"
      ref="ruleFormRef"
      :model="formData"
      :rules="rules"
      label-width="120px"
      runningStatus-icon
      :inline="true"
    >
      <div class="form-group-title">基本信息</div>
      <div class="form-item-info">
        <!-- <el-form-item class="form-itme-width_20" label="项目名称" id="projectId" prop="projectId">
          <dc-select-remote
            v-model="formData.projectId"
            placeholder="请选择项目"
            objectName="project"
            :multiple="false"
            :multiple-limit="1"
            :clearable="true"
          />
        </el-form-item> -->
        <el-form-item
          class="form-itme-width_20"
          label="配置模板"
          id="projectId"
          prop="projectId"
          @click="openProjectList"
        >
          <el-input
            :value="proxy.getKeyObject(PROJECT_MAP_CACHE, formData.projectId, 'projectName')"
            placeholder="请选择配置模板"
            clearable
          />
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="单据类型"
          id="fBillTypeId"
          prop="fBillTypeId"
        >
          <el-select
            v-model="formData.fBillTypeId"
            clearable
            placeholder="请选择单据类型"
            @change="handleBillTypeChange"
          >
            <el-option-group v-for="group in groupedOptions" :key="group.id" :label="group.label">
              <el-option
                v-for="option in group.children"
                :key="option.id"
                :label="option.label"
                :value="option.dictKey"
              />
            </el-option-group>
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="销售组织"
          id="fSaleOrgDictId"
          prop="fSaleOrgDictId"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-select v-model="formData.fSaleOrgDictId" clearable @change="handleSaleOrgChange">
            <el-option
              v-for="item in ORG_LIST_CACHE"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="预测组织"
          id="fForeOrgDictId"
          prop="fForeOrgDictId"
          v-else
        >
          <el-select v-model="formData.fForeOrgDictId" clearable @change="handleFForeOrgChange">
            <el-option
              v-for="item in ORG_LIST_CACHE"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            />
          </el-select>
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="销售员" id="fSalerId" prop="fSalerId">
          <el-select
            v-model="formData.fSalerId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入人员名称进行搜索"
            :remote-method="remoteSalersOptions"
            clearable
            @change="handleFSalerChange"
          >
            <el-option
              v-for="item in SalersOptions"
              :key="item.fnumber"
              :label="item.fname"
              :value="item.fnumber"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="销售部门"
          id="fSaleDeptName"
          prop="fSaleDeptName"
        >
          <el-input
            v-model="formData.fSaleDeptName"
            placeholder="选择销售员自动获取"
            clearable
            disabled
          />
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="日期" id="fDate" prop="fDate">
          <el-date-picker
            v-model="formData.fDate"
            type="date"
            clearable
            placeholder="请选择时间"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="客户" id="fCustId" prop="fCustId">
          <el-select
            v-model="formData.fCustId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入客户名称进行搜索"
            :remote-method="remoteCustomerOptions"
            @change="handleCustomerChange"
            clearable
          >
            <el-option
              v-for="item in customerOptions"
              :key="item.customerFNumber"
              :label="item.customerFName"
              :value="item.customerFNumber"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="变更原因"
          id="fChangeReason"
          prop="fChangeReason"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fChangeReason" placeholder="请输入变更原因" clearable />
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="利润中心"
          id="fQlktText1"
          prop="fQlktText1"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fQlktText1" placeholder="请输入利润中心" clearable />
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="业务类型"
          id="fBusinessType"
          prop="fBusinessType"
        >
          <el-input v-model="formData.fBusinessType" placeholder="请输入业务类型" clearable />
        </el-form-item>
        <el-form-item class="form-itme-width_20" label="终端客户" id="fOraBase" prop="fOraBase">
          <el-select
            v-model="formData.fOraBase"
            filterable
            remote
            reserve-keyword
            placeholder="请输入终端客户进行搜索"
            :remote-method="remoteCustomerOptions"
            clearable
          >
            <el-option
              v-for="item in customerOptions"
              :key="item.customerFNumber"
              :label="item.customerFName"
              :value="item.customerFNumber"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="结算币种"
          id="fSettleCurrId"
          prop="fSettleCurrId"
        >
          <el-select
            v-model="formData.fSettleCurrId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入币种进行搜索"
            :remote-method="remoteCurrenciesOptions"
            clearable
          >
            <el-option
              v-for="item in currenciesOptinons"
              :key="item.id"
              :label="item.currencyName"
              :value="item.currencyCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="交货方式"
          id="fBdkText7"
          prop="fBdkText7"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-select v-model="formData.fHeadDeliveryWay" clearable placeholder="请选择交货方式">
            <el-option
              v-for="item in fHeadDeliveryWayType"
              :key="item.id"
              :label="item.bizValue"
              :value="item.bizKey"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="库别"
          id="fQlktText2"
          prop="fQlktText2"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fQlktText2" placeholder="请输入库别" clearable />
        </el-form-item>
        <el-form-item class="form-itme-width_20" label="TPM" id="fTpm" prop="fTpm">
          <el-select
            v-model="formData.fTpm"
            filterable
            remote
            reserve-keyword
            placeholder="请输入人员名称进行搜索"
            :remote-method="remoteTpmOptions"
            @change="handleFTpmChange"
            clearable
          >
            <el-option
              v-for="item in tpmOptions"
              :key="item.fnumber"
              :label="item.fname"
              :value="item.fnumber"
            />
          </el-select>
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="项目类型" prop="fBdkText7">
          <el-select v-model="formData.fBdkText7" clearable placeholder="请选择项目类型">
            <el-option
              v-for="item in fEwProjectTypeOptions"
              :key="item.id"
              :label="item.bizValue"
              :value="item.bizKey"
            />
          </el-select>
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="订单类型" id="fOraCombo" prop="fOraCombo">
          <el-select v-model="formData.fOraCombo" clearable placeholder="请选择订单类型">
            <el-option
              v-for="item in DC_PMS_PROJECT_ORDER"
              :key="item.dictValue"
              :label="item.dictValue"
              :value="item.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="收款条件"
          id="fRecConditionId"
          prop="fRecConditionId"
        >
          <el-select
            v-model="formData.fRecConditionId"
            filterable
            remote
            placeholder="请输入收款条件进行搜索"
            :remote-method="remoteCollectionTermsOptions"
            clearable
          >
            <el-option
              v-for="item in CollectionTermsOptions"
              :key="item.id"
              :label="item.fname"
              :value="item.fcode"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="升级"
          id="fEwUpgrad"
          prop="fEwUpgrad"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-select v-model="formData.fEwUpgrad" clearable>
            <el-option
              v-for="item in ooptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="厂商地址"
          id="fQlktText3"
          prop="fQlktText3"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fQlktText3" placeholder="请输入厂商地址" clearable />
        </el-form-item>
        <el-form-item class="form-itme-width_20" label="研发订单" id="fEwIsDev" prop="fEwIsDev">
          <el-select v-model="formData.fEwIsDev" clearable placeholder="请选择研发订单">
            <el-option
              v-for="item in ooptions"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="联系人"
          id="fQlktText4"
          prop="fQlktText4"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fQlktText4" placeholder="请输入联系人" clearable />
        </el-form-item>
        <el-form-item class="form-itme-width_20" label="运营跟单" id="fOraText3" prop="fOraText3">
          <el-select
            v-model="formData.fOraText3"
            filterable
            remote
            reserve-keyword
            placeholder="请输入运营跟单进行搜索"
            :remote-method="remoteDocumentariesOptions"
            clearable
          >
            <el-option
              v-for="item in documentariesOptions"
              :key="item.fnumber"
              :label="item.fname"
              :value="item.fnumber"
            />
          </el-select>
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="项目编号" id="fBdkBase" prop="fBdkBase">
          <el-select
            v-model="formData.fBdkBase"
            filterable
            remote
            reserve-keyword
            placeholder="请输入项目编号进行搜索"
            :remote-method="remoteProjectNumbersOptions"
            clearable
          >
            <el-option
              v-for="item in projectNumbersOptions"
              :key="item.id"
              :label="item.fname"
              :value="item.fnumber"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="是否含税"
          id="fIsIncludedTax"
          prop="fIsIncludedTax"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-select v-model="formData.fIsIncludedTax" clearable placeholder="请选择是否含税">
            <el-option
              v-for="item in ooptions"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          class="form-itme-width_20"
          label="电话"
          id="fQlktText5"
          prop="fQlktText5"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fQlktText5" placeholder="请输入电话" clearable />
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="采购" id="fBdkText6" prop="fBdkText6">
          <el-input v-model="formData.fBdkText6" placeholder="请输入采购" clearable />
        </el-form-item>

        <el-form-item class="form-itme-width_20" label="备注" id="fNote" prop="fNote">
          <el-input v-model="formData.fNote" placeholder="请输入备注" clearable />
        </el-form-item>

        <el-form-item
          class="form-itme-width_20"
          label="收货地址"
          id="fOraBase2"
          prop="fOraBase2"
          v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
        >
          <el-input v-model="formData.fOraBase2" placeholder="请输入收货地址" clearable />
        </el-form-item>
      </div>
    </el-form>
  </div>
  <div class="form-group-title form-group-header-title">销售订单明细</div>
  <div class="form-group-header-btn">
    <el-button type="primary" plain @click="handleAdd" v-if="formData.editStatus == true"
      >新增</el-button
    >
    <el-button @click="handleDelete" v-if="formData.editStatus == true">删除</el-button>
    <el-button @click="handleCtrlC" v-if="formData.editStatus == true">复制行</el-button>
  </div>
  <el-form
    ref="ruleTableRef"
    class="detail-table"
    :model="formData.dcErpOrderItemList[numberIndex]"
  >
    <!-- 预测单表格 -->
    <el-table
      ref="singleSelectTable"
      :data="formData.dcErpOrderItemList"
      @row-dblclick="handleRowDbclick"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      v-if="formData.fParentBillTypeDictId == '1870708551385808898'"
      class="text-align"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="序号" width="60" type="index" align="center">
        <template #default="scoped">
          <span>{{ (queryParams.current - 1) * queryParams.size + scoped.$index + 1 }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="fSupplyOrgId"
        label="供应组织"
        align="center"
        width="150"
        show-overflow-tooltip
      >
        <template #default="scoped">
          {{ scoped.row.fSupplyOrgDictName }}
        </template>
      </el-table-column>

      <el-table-column
        prop="fCustIdName"
        label="客户"
        align="center"
        width="150"
        show-overflow-tooltip
      />

      <!-- <el-table-column
        prop="fEwGroupCust"
        label="对应集团客户"
        align="center"
        width="150"
        show-overflow-tooltip
      /> -->

      <el-table-column
        prop="fMaterialId"
        label="物料编码"
        align="center"
        width="150"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fMaterialId"
            :rules="{ required: true, message: '请选择物料编码', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fMaterialId"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteFMaterialOptions"
              @change="handleFMaterialChange(scoped.row)"
              clearable
            >
              <el-option
                v-for="item in materialsOptinons"
                :key="item.id"
                :label="item.fnumber"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fMaterialId }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fMaterialName"
        label="物料名称"
        align="center"
        width="130"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fMaterialName"
            :rules="{ required: true, message: '请选择物料名称', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fMaterialName"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteMaterialsOptions"
              @change="handleMaterialChange(scoped.row)"
              clearable
            >
              <el-option
                v-for="item in materialsOptinons"
                :key="item.id"
                :label="item.fname"
                :value="item.fname"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fMaterialName }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fMaterialModel"
        label="规格型号"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <!-- <el-table-column prop="fBomId" label="BOM版本 " align="center" /> -->
      <el-table-column
        prop="fOraAssistant1"
        label="项目名称"
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fOraAssistant1"
            :rules="{ required: true, message: '请选择项目名称', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fOraAssistant1"
              filterable
              remote
              reserve-keyword
              placeholder="请输入项目名称进行搜索"
              :remote-method="remoteProjectNamesOptions"
              clearable
            >
              <el-option
                v-for="item in projectNamesOptions"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fOraAssistant1Name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fUnitId" label="单位" align="center" width="100">
        <template #default="scoped">
          <span>{{ scoped.row.fUnitName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fQty" label="销售数量 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fQty"
            :rules="{ required: true, message: '请选择销售数量', trigger: 'change' }"
          >
            <el-input-number v-model="scoped.row.fQty" controls-position="right" />
          </el-form-item>
          <span v-else>{{ scoped.row.fQty }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fStartDate" label="预测开始日期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fStartDate"
            :rules="{ required: true, message: '请选择预测开始日期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fStartDate"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fStartDate }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fEndDate" label="预测结束日期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEndDate"
            :rules="{ required: true, message: '请选择预测结束日期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fEndDate"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fEndDate }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fMtoNo" label="计划跟踪号" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fMtoNo">
            <el-input v-model="scoped.row.fMtoNo" placeholder="请输入计划跟踪号" clearable />
          </el-form-item>
          <span v-else>{{ scoped.row.fMtoNo }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="ff100001" label="喷砂亮银" align="center" />

      <el-table-column prop="fAveraType" label="均化类型" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fAveraType"
            :rules="{ required: true, message: '请输入均化类型', trigger: 'change' }"
          >
            <el-select v-model="scoped.row.fAveraType" clearable placeholder="请选择均化类型">
              <el-option
                v-for="item in fAveraTypeType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fAveraTypeName }}
          </span>
        </template>
      </el-table-column>

      <el-table-column prop="fAveraCycle" label="均化周期" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fAveraCycle"
            :rules="{ required: true, message: '请输入均化周期', trigger: 'change' }"
          >
            <el-input-number v-model="scoped.row.fAveraCycle" controls-position="right" />
          </el-form-item>
          <span v-else>{{ scoped.row.fAveraCycle }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="fStockOrgId"
        label="库存组织"
        show-overflow-tooltip
        align="center"
        width="180"
      >
        <template #default="scoped">
          <span>
            {{ scoped.row.fStockOrgDictName }}
          </span>
        </template>
      </el-table-column>

      <!-- <el-table-column prop="fOwnerTypeId" label="货主类型" align="center" /> -->

      <el-table-column
        prop="fOwnerId"
        label="货主"
        show-overflow-tooltip
        align="center"
        width="180"
      >
        <template #default="scoped">
          <span>
            {{ scoped.row.fOwnerDictName }}
          </span>
        </template>
      </el-table-column>

      <el-table-column prop="fReserveType" label="预留类型" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fReserveType"
            :rules="{ required: true, message: '请输入预留类型', trigger: 'change' }"
          >
            <el-select v-model="scoped.row.fReserveType" clearable placeholder="请选择预留类型">
              <el-option
                v-for="item in reservationType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fReserveTypeName }}
          </span>
        </template>
      </el-table-column>

      <!-- <el-table-column prop="fPriority" label="需求优先级" align="center" /> -->

      <el-table-column prop="fEntryNote" label="备注" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fEntryNote">
            <el-input v-model="scoped.row.fEntryNote" placeholder="请输入备注" clearable />
          </el-form-item>
          <span v-else>{{ scoped.row.fEntryNote }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fExchangeRate" label="汇率" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fExchangeRate">
            <el-input-number v-model="scoped.row.fExchangeRate" controls-position="right" />
          </el-form-item>
          <span v-else>{{ scoped.row.fExchangeRate }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fSettleCurrIdName" label="结算币种" align="center" />

      <el-table-column prop="fOraTaxRate" label="税率" align="center" width="180">
        <template #default="scoped">
          <el-input-number
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fOraTaxRate"
            controls-position="right"
          />
          <span v-else>{{ scoped.row.fOraTaxRate }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fCostAttrMtoNo" label="项目编号" align="center" width="180">
        <template #default="scoped">
          <el-select
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fCostAttrMtoNo"
            filterable
            remote
            reserve-keyword
            placeholder="请输入项目编号进行搜索"
            :remote-method="remoteProjectNumbersOptions"
            clearable
          >
            <el-option
              v-for="item in projectNumbersOptions"
              :key="item.id"
              :label="item.fname"
              :value="item.fname"
            />
          </el-select>
          <span v-else>{{ scoped.row.fCostAttrMtoNo }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fBdkText8" label="内部PM" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText8"
            placeholder="请选择内部PM"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText8" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText9" label="机构工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText9"
            placeholder="请选择机构工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText9" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText10" label="电气工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText10"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText10" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText11" label="电子工程师" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText11"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText11" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText12" label="软件工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText12"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText12" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fBusinessDivisionId" label="事业部" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBusinessDivisionId"
            placeholder="请输入"
            clearable
          />
          <span v-else>{{ scoped.row.fBusinessDivisionId }}</span>
        </template>
      </el-table-column> -->

      <el-table-column prop="fEwTpm" label="TPM " align="center" width="180">
        <template #default="scoped">
          <!-- <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwTpm"
            :rules="{ required: true, message: '请输入TPM', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwTpm"
              filterable
              remote
              reserve-keyword
              placeholder="请输入人员名称进行搜索"
              :remote-method="remoteTpmOptions"
              clearable
            >
              <el-option
                v-for="item in tpmOptions"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item> -->
          <span>{{ scoped.row.fEwTpmName }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fBdkBase1Name" label="销售员 " align="center" />

      <el-table-column
        prop="fEwSaleDeptIdName"
        label="销售部门"
        align="center"
        show-overflow-tooltip
      />

      <!-- <el-table-column
        prop="fBdkBaseProperty"
        label="旧物料编码"
        align="center"
        width="180"
        show-overflow-tooltip
      /> -->

      <el-table-column prop="fQlktDate" label="客户下单日期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fQlktDate"
            :rules="{ required: true, message: '请选择客户下单日期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fQlktDate"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fQlktDate }}</span>
        </template>
      </el-table-column>
      <!-- 
      <el-table-column prop="fDeliveryDate" label="要货日期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fDeliveryDate"
            :rules="{ required: true, message: '请选择要货日期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fDeliveryDate"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fDeliveryDate }}</span>
        </template>   
      </el-table-column> -->

      <el-table-column prop="fOraText5" label="客户交期ETA" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fOraText5"
            :rules="{ required: true, message: '请选择客户交期ETA', trigger: 'change' }"
          >
            <el-date-picker
              v-if="editRowIndex === scoped.$index"
              v-model="scoped.row.fOraText5"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else>{{ scoped.row.fOraText5 }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="fEwProjectTypeName"
        label="项目"
        align="center"
        width="180"
        show-overflow-tooltip
      />

      <el-table-column
        prop="fOraCombo"
        label="订单类型"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <!-- 
      <el-table-column prop="fBdkText1" label="客户物料代码" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText1"
            placeholder="请输入客户物料代码"
            clearable
          />
          <span v-else>{{ scoped.row.fBdkText1 }}</span>
        </template>
      </el-table-column> -->

      <el-table-column prop="fBdkText2" label="客户物料名称" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText2"
            placeholder="请输入客户物料名称"
            clearable
          />
          <span v-else>{{ scoped.row.fBdkText2 }}</span>
        </template>
      </el-table-column>

      <!-- <el-table-column prop="fBdkText14" label="客户规格型号" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText14"
            placeholder="请输入客户规格型号"
            clearable
          />
          <span v-else>{{ scoped.row.fBdkText14 }}</span>
        </template>
      </el-table-column> -->

      <el-table-column prop="fEwPhase" label="阶段" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwPhase"
            :rules="{ required: true, message: '请选择阶段', trigger: 'change' }"
          >
            <el-select
              v-if="editRowIndex === scoped.$index"
              v-model="scoped.row.fEwPhase"
              clearable
              placeholder="请选择阶段"
            >
              <el-option
                v-for="item in stageType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fEwPhaseName }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="fOraBase4Name"
        label="终端客户"
        align="center"
        width="180"
        show-overflow-tooltip
      />

      <!-- <el-table-column prop="fOraDate1" label="要求齐套日 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fOraDate1"
            :rules="{ required: true, message: '请选择要求齐套日', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fOraDate1"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fOraDate1 }}</span>
        </template>
      </el-table-column> -->

      <!-- <el-table-column prop="fOraQty" label="库存" align="center" width="180">
        <template #default="scoped">
          <span>{{ scoped.row.fOraQty }}</span>
        </template>
      </el-table-column> -->

      <el-table-column prop="fOraText4" label="PM回复交期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fOraText4"
            :rules="{ required: true, message: '请选择PM回复交期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fOraText4"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fOraText4 }}</span>
        </template>
      </el-table-column>

      <el-table-column prop="fEwCostType" label="成本类型" align="center" width="180">
        <template #default="scoped">
          <el-select
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fEwCostType"
            clearable
            placeholder="请选择成本类型"
          >
            <el-option
              v-for="item in costType"
              :key="item.id"
              :label="item.bizValue"
              :value="item.bizKey"
            />
          </el-select>
          <span v-else>
            {{ scoped.row.fEwCostTypeName }}
          </span>
        </template>
      </el-table-column>

      <el-table-column prop="fEwInternalEtd" label="内部ETD" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fEwInternalEtd"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fEwInternalEtd }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwMerchandiserEtd" label="回复跟单ETD" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fEwMerchandiserEtd"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fEwMerchandiserEtd }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwIsCustomsDeclaration" label="是否报关" align="center">
        <template #default="scoped">
          <el-checkbox
            v-model="scoped.row.fEwIsCustomsDeclaration"
            v-if="editRowIndex === scoped.$index"
          />
          <el-checkbox v-model="scoped.row.fEwIsCustomsDeclaration" v-else disabled />
        </template>
      </el-table-column>
      <el-table-column prop="fEwIsMrpRun" label="是否需要运算" align="center">
        <template #default="scoped">
          <el-checkbox v-model="scoped.row.fEwIsMrpRun" v-if="editRowIndex === scoped.$index" />
          <el-checkbox v-model="scoped.row.fEwIsMrpRun" v-else disabled />
        </template>
      </el-table-column>
      <el-table-column prop="fEwIsPreStock" label="是否需要备料" align="center">
        <template #default="scoped">
          <el-checkbox v-model="scoped.row.fEwIsPreStock" v-if="editRowIndex === scoped.$index" />
          <el-checkbox v-model="scoped.row.fEwIsPreStock" v-else disabled />
        </template>
      </el-table-column>

      <el-table-column prop="fEwCustomerProduct" label="客户产品" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwCustomerProduct"
            :rules="{ required: true, message: '请选择客户产品', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwCustomerProduct"
              clearable
              placeholder="请选择成本类型"
            >
              <el-option
                v-for="item in productSeriationType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwCustomerProduct }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="项目类型" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwProjectType"
            :rules="{ required: true, message: '请选择项目类型', trigger: 'change' }"
          >
            <el-select v-model="scoped.row.fEwProjectType" clearable placeholder="请选择项目类型">
              <el-option
                v-for="item in fEwProjectTypeOptions"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwProjectTypeName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="设备属性" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwDeviceAttribute"
            :rules="{ required: true, message: '请选择设备属性', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwDeviceAttribute"
              clearable
              placeholder="请选择设备属性"
            >
              <el-option
                v-for="item in fEwDeviceAttributeOptinos"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwDeviceAttributeName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwProducSeriesId" label="产品系列" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwProducSeriesId"
            :rules="{ required: true, message: '请输入产品系列', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwProducSeriesId"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteProductSeriationOptions"
              clearable
            >
              <el-option
                v-for="item in ProductSeriationOptinos"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fEwProducSeriesName }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" fixed="right" width="180">
        <template #default="scoped">
          <div v-if="editRowIndex === scoped.$index">
            <el-form-item>
              <el-button text type="success" @click="configSubmit(scoped.row)">确定</el-button>
              <el-button text type="success" @click="Cancel(scoped.row, scoped.$index)"
                >取消</el-button
              >
            </el-form-item>
          </div>
        </template>
      </el-table-column>
    </el-table>
    <!-- 销售单表格 -->
    <el-table
      ref="singleSelectTable"
      :data="formData.dcErpOrderItemList"
      @row-dblclick="handleRowDbclick"
      @selection-change="handleSelectionChange"
      @row-click="handleRowClick"
      v-else
    >
      <el-table-column type="selection" width="55" />
      <el-table-column label="序号" width="60" type="index" align="center">
        <template #default="scoped">
          <span>{{ (queryParams.current - 1) * queryParams.size + scoped.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fMaterialId"
        label="物料编码"
        align="center"
        width="150"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fMaterialId"
            :rules="{ required: true, message: '请选择物料编码', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fMaterialId"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteFMaterialOptions"
              @change="handleFMaterialChange(scoped.row)"
              clearable
            >
              <el-option
                v-for="item in materialsOptinons"
                :key="item.id"
                :label="item.fnumber"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fMaterialId }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fMaterialName"
        label="物料名称"
        align="center"
        width="130"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fMaterialName"
            :rules="{ required: true, message: '请选择物料名称', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fMaterialName"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteMaterialsOptions"
              @change="handleMaterialChange(scoped.row)"
              clearable
            >
              <el-option
                v-for="item in materialsOptinons"
                :key="item.id"
                :label="item.fname"
                :value="item.fname"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fMaterialName }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="contactsDeptName" label="存货类别" align="center" /> -->
      <el-table-column
        prop="fMaterialModel"
        label="规格型号"
        align="center"
        width="180"
        show-overflow-tooltip
      />
      <el-table-column prop="fIsPrecisionPart" label="精密件" align="center" />
      <el-table-column prop="ff100001" label="喷砂亮银" align="center" />
      <el-table-column
        prop="fVersionNo"
        label="版本号"
        align="center"
        width="180"
        v-if="formData.fParentBillTypeDictId == '1870708016893067265'"
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fVersionNo"
            :rules="{ required: true, message: '请选择版本号', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fVersionNo"
              clearable
              v-if="editRowIndex === scoped.$index"
            >
              <el-option
                v-for="item in fVersionNoType"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fVersionNo }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fUnitId" label="单位" align="center" width="100">
        <template #default="scoped">
          <span>{{ scoped.row.fUnitName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fQty" label="销售数量 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fQty"
            :rules="{ required: true, message: '请选择销售数量', trigger: 'change' }"
          >
            <el-input-number
              v-if="editRowIndex === scoped.$index"
              v-model="scoped.row.fQty"
              controls-position="right"
            />
          </el-form-item>
          <span v-else>{{ scoped.row.fQty }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fIsFree" label="是否赠品 " align="center" width="130">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fIsFree">
            <el-select v-model="scoped.row.fIsFree" clearable>
              <el-option
                v-for="item in ooptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <span v-else>
            <span v-if="scoped.row.fIsFree === false">否</span>
            <span v-else>是</span></span
          >
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fDeliveryDate" label="要货日期 " align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fDeliveryDate"
            :rules="{ required: true, message: '请选择要货日期', trigger: 'change' }"
          >
            <el-date-picker
              v-model="scoped.row.fDeliveryDate"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>

          <span v-else> {{ scoped.row.fDeliveryDate }}</span>
        </template>
      </el-table-column> -->
      <el-table-column prop="fOraText5" label="客户交期ETA" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fOraText5">
            <el-date-picker
              v-model="scoped.row.fOraText5"
              type="date"
              placeholder="请选择日期"
              format="YYYY/MM/DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
          <span v-else>{{ scoped.row.fOraText5 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fStockOrgId"
        label="库存组织 "
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fStockOrgId">
            <el-select
              v-model="scoped.row.fStockOrgDictId"
              clearable
              @change="handleFStockOrgIdChange"
            >
              <el-option
                v-for="item in ORG_LIST_CACHE"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fStockOrgDictName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        prop="fPeSettleOrgId"
        label="结算组织 "
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <span>
            {{ scoped.row.fPeSettleOrgDictName }}
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fBomId" label="BOM版本 " align="center" /> -->
      <!-- <el-table-column prop="fOwnerTypeId" label="货主类型 " align="center" /> -->
      <el-table-column
        prop="fOwnerId"
        label="货主"
        align="center"
        show-overflow-tooltip
        width="180"
      >
        <template #default="scoped">
          <span>
            {{ scoped.row.fOwnerDictName }}
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fOraPrice" label="核价" align="center" /> -->
      <el-table-column prop="fEntryNote" label="备注" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fMtoNo">
            <el-input v-model="scoped.row.fEntryNote" placeholder="请输入" clearable />
          </el-form-item>
          <span v-else>{{ scoped.row.fEntryNote }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fMtoNo" label="计划跟踪号" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fMtoNo">
            <el-input v-model="scoped.row.fMtoNo" placeholder="请输入" clearable />
          </el-form-item>
          <span v-else>{{ scoped.row.fMtoNo }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fBdkText" label="实际品名" align="center" /> -->
      <!-- <el-table-column prop="fBdkText1" label="客户物料代码" align="center" /> -->
      <el-table-column prop="fBdkText2" label="客户物料名称" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fBdkText2">
            <el-input v-model="scoped.row.fBdkText2" placeholder="请输入" clearable />
          </el-form-item>
          <span v-else>{{ scoped.row.fBdkText2 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText3" label="客户PO" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fBdkText3"
            :rules="{ required: true, message: '请输入客户PO', trigger: 'change' }"
          >
            <el-input v-model="scoped.row.fBdkText3" placeholder="请输入" clearable />
          </el-form-item>

          <span v-else>{{ scoped.row.fBdkText3 }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fBdkText4" label="客户ID" align="center" /> -->
      <!-- <el-table-column prop="fBdkText5" label="成品和模组料号" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText5"
            placeholder="请输入"
            clearable
          />
          <span v-else>{{ scoped.row.fBdkText5 }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="fBdkBaseProperty" label="旧物料编码" align="center" /> -->
      <el-table-column prop="fBdkText8" label="内部PM" align="center" width="180">
        <template #default="scoped">
          <el-form-item v-if="editRowIndex === scoped.$index" prop="fBdkText8">
            <dc-select-user
              v-model="scoped.row.fBdkText8"
              placeholder="请选择内部PM"
              returnType="string"
              :multiple="false"
              :multiple-limit="1"
            />
          </el-form-item>
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText8" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText9" label="机构工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText9"
            placeholder="请选择机构工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText9" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText10" label="电气工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText10"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText10" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText11" label="电子工程师" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText11"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText11" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <el-table-column prop="fBdkText12" label="软件工程" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBdkText12"
            placeholder="请选择电气工程"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fBdkText12" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fBusinessDivisionId" label="事业部" align="center" width="180">
        <template #default="scoped">
          <el-input
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fBusinessDivisionId"
            placeholder="请输入"
            clearable
          />
          <span v-else>{{ scoped.row.fBusinessDivisionId }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="fBdkText14" label="客户规格型号" align="center" /> -->
      <el-table-column prop="fQlktDate" label="客户下单日期" align="center" />
      <el-table-column prop="fPersonLiable" label="责任人" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fPersonLiable"
            :rules="{ required: true, message: '请输入责任人', trigger: 'change' }"
          >
            <el-input v-model="scoped.row.fPersonLiable" placeholder="请输入责任人" />
          </el-form-item>

          <span v-else> {{ scoped.row.fPersonLiable }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fQlktText6" label="请购部门" align="center" /> -->
      <!-- <el-table-column prop="fQlktText7" label="2D" align="center" />
      <el-table-column prop="fQlktText8" label="Catagory" align="center" />
      <el-table-column prop="fQlktText9" label="订单项次号" align="center" /> -->
      <!-- <el-table-column prop="fQlktText10" label="请购人" align="center" />
      <el-table-column prop="fOraCheckbox" label="是否手工已推应收 " align="center" /> -->
      <el-table-column prop="fEwProducSeriesId" label="产品系列" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwProducSeriesId"
            :rules="{ required: true, message: '请输入产品系列', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwProducSeriesId"
              filterable
              remote
              reserve-keyword
              :remote-method="remoteProductSeriationOptions"
              clearable
            >
              <el-option
                v-for="item in ProductSeriationOptinos"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fEwProducSeriesName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwPhase" label="阶段" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwPhase"
            :rules="{ required: true, message: '请选择阶段', trigger: 'change' }"
          >
            <el-select
              v-if="editRowIndex === scoped.$index"
              v-model="scoped.row.fEwPhase"
              clearable
              placeholder="请选择阶段"
            >
              <el-option
                v-for="item in stageType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fEwPhaseName }}</span>
        </template>
      </el-table-column>

      <el-table-column
        prop="fOraAssistant1"
        label="项目名称"
        align="center"
        width="180"
        show-overflow-tooltip
      >
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fOraAssistant1"
            :rules="{ required: true, message: '请选择项目名称', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fOraAssistant1"
              filterable
              remote
              reserve-keyword
              placeholder="请输入项目名称进行搜索"
              :remote-method="remoteProjectNamesOptions"
              clearable
            >
              <el-option
                v-for="item in projectNamesOptions"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item>
          <span v-else>{{ scoped.row.fOraAssistant1Name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fOraDate" label="源单日期" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fOraDate"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fOraDate }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fOraDate1" label="要求齐套日" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fOraDate1"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fOraDate1 }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fOraQty" label="库存" align="center" width="180">
        <template #default="scoped">
          <span>{{ scoped.row.fOraQty }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column prop="fOraText2" label="跟单" align="center" /> -->
      <!-- <el-table-column prop="fOraText4" label="PM回复交期" align="center" /> -->
      <el-table-column prop="fOraText5" label="客户交期ETA" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fOraText5"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fOraText5 }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fOraCombo1" label="是否验收" align="center" />
      <!-- <el-table-column prop="fPersonLiable" label="负责人" align="center" width="180">
        <template #default="scoped">
          <dc-select-user
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fPersonLiable"
            placeholder="请选择负责人"
            returnType="string"
            :multiple="false"
            :multiple-limit="1"
          />
          <span v-else>
            <dc-view v-model="scoped.row.fPersonLiable" objectName="user" showKey="realName"
          /></span>
        </template>
      </el-table-column> -->
      <el-table-column prop="fCostAttrMtoNo" label="成本归属专案" align="center" width="180">
        <template #default="scoped">
          <el-select
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fCostAttrMtoNo"
            filterable
            remote
            reserve-keyword
            placeholder="请输入项目名称进行搜索"
            :remote-method="remoteProjectNumbersOptions"
            clearable
          >
            <el-option
              v-for="item in projectNumbersOptions"
              :key="item.id"
              :label="item.fname"
              :value="item.fname"
            />
          </el-select>
          <span v-else>{{ scoped.row.fCostAttrMtoNo }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwTpm" label="TPM " align="center" width="180">
        <template #default="scoped">
          <!-- <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwTpm"
            :rules="{ required: true, message: '请输入TPM', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwTpm"
              filterable
              remote
              reserve-keyword
              placeholder="请输入人员名称进行搜索"
              :remote-method="remoteTpmOptions"
              clearable
            >
              <el-option
                v-for="item in tpmOptions"
                :key="item.id"
                :label="item.fname"
                :value="item.fnumber"
              />
            </el-select>
          </el-form-item> -->
          <span>{{ scoped.row.fEwTpmName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwCostType" label="成本类型" align="center" width="180">
        <template #default="scoped">
          <el-select
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fEwCostType"
            clearable
            placeholder="请选择成本类型"
          >
            <el-option
              v-for="item in costType"
              :key="item.id"
              :label="item.bizValue"
              :value="item.bizKey"
            />
          </el-select>
          <span v-else>
            {{ scoped.row.fEwCostTypeName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwFreeReason" label="免费原因" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwFreeReason"
            :rules="{ required: true, message: '请输入免费原因', trigger: 'change' }"
          >
            <el-select v-model="scoped.row.fEwFreeReason" clearable placeholder="请选择免费原因">
              <el-option
                v-for="item in fEwFreeReasonType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwFreeReasonName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="fEwInternalEtd" label="内部ETD" align="center" width="180">
        <template #default="scoped">
          <el-date-picker
            v-if="editRowIndex === scoped.$index"
            v-model="scoped.row.fEwInternalEtd"
            type="date"
            placeholder="请选择日期"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
          />
          <span v-else>{{ scoped.row.fEwInternalEtd }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="fEwMerchandiserEtd" label="回复跟单ETD" align="center" /> -->
      <el-table-column prop="fEwIsCustomsDeclaration" label="是否报关" align="center">
        <template #default="scoped">
          <el-checkbox
            v-model="scoped.row.fEwIsCustomsDeclaration"
            v-if="editRowIndex === scoped.$index"
          />
          <el-checkbox v-model="scoped.row.fEwIsCustomsDeclaration" v-else disabled />
        </template>
      </el-table-column>
      <el-table-column prop="fEwIsMrpRun" label="是否需要运算" align="center">
        <template #default="scoped">
          <el-checkbox v-model="scoped.row.fEwIsMrpRun" v-if="editRowIndex === scoped.$index" />
          <el-checkbox v-model="scoped.row.fEwIsMrpRun" v-else disabled />
        </template>
      </el-table-column>
      <el-table-column prop="fEwIsPreStock" label="是否需要备料" align="center">
        <template #default="scoped">
          <el-checkbox v-model="scoped.row.fEwIsPreStock" v-if="editRowIndex === scoped.$index" />
          <el-checkbox v-model="scoped.row.fEwIsPreStock" v-else disabled />
        </template>
      </el-table-column>
      <el-table-column prop="fEwCustomerProduct" label="客户产品" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwCustomerProduct"
            :rules="{ required: true, message: '请选择客户产品', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwCustomerProduct"
              clearable
              placeholder="请选择成本类型"
            >
              <el-option
                v-for="item in productSeriationType"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwCustomerProduct }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="项目类型" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwProjectType"
            :rules="{ required: true, message: '请选择项目类型', trigger: 'change' }"
          >
            <el-select v-model="scoped.row.fEwProjectType" clearable placeholder="请选择项目类型">
              <el-option
                v-for="item in fEwProjectTypeOptions"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwProjectTypeName }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="设备属性" align="center" width="180">
        <template #default="scoped">
          <el-form-item
            v-if="editRowIndex === scoped.$index"
            prop="fEwDeviceAttribute"
            :rules="{ required: true, message: '请选择设备属性', trigger: 'change' }"
          >
            <el-select
              v-model="scoped.row.fEwDeviceAttribute"
              clearable
              placeholder="请选择设备属性"
            >
              <el-option
                v-for="item in fEwDeviceAttributeOptinos"
                :key="item.id"
                :label="item.bizValue"
                :value="item.bizKey"
              />
            </el-select>
          </el-form-item>
          <span v-else>
            {{ scoped.row.fEwDeviceAttributeName }}
          </span>
        </template>
      </el-table-column>

      <el-table-column align="center" fixed="right" width="180">
        <template #default="scoped">
          <div v-if="editRowIndex === scoped.$index">
            <el-form-item>
              <el-button text type="success" @click="configSubmit(scoped.row)">确定</el-button>
              <el-button text type="success" @click="Cancel(scoped.row, scoped.$index)"
                >取消</el-button
              >
            </el-form-item>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-form class="custom-form" label-width="120px" :inline="true" v-if="info.createUser != null">
      <div class="form-item-info mt-5 form-display">
        <el-form-item label="发起人">
          <dc-view v-model="info.createUser" objectName="user"
        /></el-form-item>
        <el-form-item label="发起时间">
          {{ info.createTime }}
        </el-form-item>
        <el-form-item label="发起部门">
          <dc-view v-model="info.createDept" objectName="dept"
        /></el-form-item>
      </div>
    </el-form>

    <el-form-item class="form-itme-width_100">
      <el-button @click="submit" v-if="formData.editStatus == true">保存</el-button>
      <el-button type="primary" @click="passSubmit" v-if="formData.editStatus == true"
        >提交</el-button
      >
      <el-button type="danger" @click="rejectSubmit" v-if="formData.editStatus == true"
        >驳回</el-button
      >
    </el-form-item>
  </el-form>
  <!--项目列表-->
  <ExecutionList :isDialog="true" @confirm="confirmProjectList" ref="ProjectListRef" />
</template>

<script setup name="executionSubmit">
import Api from '@/api';
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import { debounce } from 'lodash-es';

const { proxy } = getCurrentInstance();
const route = useRoute();
const router = useRouter();
const pageData = reactive({
  loading: false,
  queryParams: {
    current: 1,
    size: 10,
  },
  formData: {},
  ProjectListRef: null,

  // 字典
  fHeadDeliveryWayType: [],
  reservationType: [],
  costType: [],
  stageType: [],
  productSeriationType: [],
  fAveraTypeType: [],
  // 版本号
  fVersionNoType: [
    { label: 'A', value: 'A' },
    { label: 'B', value: 'B' },
    { label: 'C', value: 'C' },
    { label: 'D', value: 'D' },
    { label: 'E', value: 'E' },
    { label: 'F', value: 'F' },
    { label: 'G', value: 'G' },
    { label: 'H', value: 'H' },
    { label: 'I', value: 'I' },
    { label: 'J', value: 'J' },
    { label: 'K', value: 'K' },
    { label: 'L', value: 'L' },
    { label: 'M', value: 'M' },
    { label: 'N', value: 'N' },
    { label: 'O', value: 'O' },
    { label: 'P', value: 'P' },
    { label: 'Q', value: 'Q' },
    { label: 'R', value: 'R' },
    { label: 'S', value: 'S' },
    { label: 'T', value: 'T' },
    { label: 'U', value: 'U' },
    { label: 'V', value: 'V' },
    { label: 'W', value: 'W' },
    { label: 'X', value: 'X' },
    { label: 'Y', value: 'Y' },
    { label: 'Z', value: 'Z' },
  ],
  /*
   * 表格字段
   */
  // 单位
  unitType: [],
  // 表格免费原因
  fEwFreeReasonType: [],
  // erp查询
  customerOptions: [],
  currenciesOptinons: [],
  // 物料编码
  materialsOptinons: [],
  ProductSeriationOptinos: [],
  // 项目名称
  projectNamesOptions: [],
  // 项目编号
  projectNumbersOptions: [],
  // tpm
  tpmOptions: [],
  // 收款条件
  CollectionTermsOptions: [],
  // 销售员
  SalersOptions: [],
  // 运营跟单
  documentariesOptions: [],
  ooptions: [
    {
      label: '是',
      value: true,
    },
    {
      label: '否',
      value: false,
    },
  ],
  fEwProjectTypeOptions: [],
  fEwDeviceAttributeOptinos: [],
  openConfig: false,
  editRowIndex: null, // 当前正在编辑的行索引
  rules: {
    fBillTypeId: { required: true, message: '请选择单据类型', trigger: 'blur' },
    fSaleOrgDictId: { required: true, message: '请选择销售组织', trigger: 'blur' },
    fSalerId: { required: true, message: '请选择销售员', trigger: 'blur' },
    fSaleDeptName: { required: true, message: '请选择销售部门', trigger: 'blur' },
    fDate: { required: true, message: '请选择日期', trigger: 'blur' },
    fCustId: { required: true, message: '请选择客户', trigger: 'blur' },
    fOraBase: { required: true, message: '请选择终端客户', trigger: 'blur' },
    fSettleCurrId: { required: true, message: '请选择结算币种', trigger: 'blur' },
    fTpm: { required: true, message: '请选择TPM', trigger: 'blur' },
    fOraCombo: { required: true, message: '请选择订单类型', trigger: 'blur' },
    fOraText3: { required: true, message: '请选择运营跟单', trigger: 'blur' },
    fBdkBase: { required: true, message: '请选择项目编号', trigger: 'blur' },
    fBdkText6: { required: true, message: '请选择采购', trigger: 'blur' },
    fBdkText7: { required: true, message: '请选择项目', trigger: 'blur' },
  },
  originalRowData: null,
  singleSelectTable: null,
  selectedRow: null,
  numberIndex: null,
});

const {
  numberIndex,
  rules,
  formData,
  queryParams,
  loading,
  ProjectListRef,
  fHeadDeliveryWayType,
  fEwFreeReasonType,
  unitType,
  costType,
  reservationType,
  stageType,
  productSeriationType,
  fAveraTypeType,
  fVersionNoType,
  customerOptions,
  currenciesOptinons,
  materialsOptinons,
  ProductSeriationOptinos,
  projectNamesOptions,
  projectNumbersOptions,
  CollectionTermsOptions,
  SalersOptions,
  tpmOptions,
  documentariesOptions,
  ooptions,
  openConfig,
  editRowIndex,
  originalRowData,
  singleSelectTable,
  selectedRow,
  fEwProjectTypeOptions,
  fEwDeviceAttributeOptinos,
} = toRefs(pageData);

const props = defineProps({
  // 详情
  info: {
    type: Object,
    default: {},
  },
});

// 数据字典
const { DC_BILL_TYPE, ORG_LIST_CACHE, DC_PMS_PROJECT_ORDER, PROJECT_MAP_CACHE } = proxy.useCache([
  { key: 'DC_BILL_TYPE' },
  { key: 'DC_PMS_PROJECT_ORDER' },
  { key: 'ORG_LIST_CACHE' },
  { key: 'PROJECT_MAP_CACHE', keyName: 'id' },
]);

onMounted(() => {
  dict();
  remoteCollectionTermsOptions();
  formData.value = props.info;
  showData();
  formData.value.fRecConditionId = formData.value.erpCustomer.collectionTermICode;
  formData.value.fRecConditionIdName = formData.value.erpCustomer.collectionTermIName;
  // 结算币种
  formData.value.fSettleCurrId = formData.value.dcErpOrderConfigure
    ? formData.value.dcErpOrderConfigure.fSettleCurrId
    : formData.value.erpCustomer.currencyCode;
  formData.value.fSettleCurrName = formData.value.dcErpOrderConfigure
    ? formData.value.dcErpOrderConfigure.fSettleCurrName
    : formData.value.erpCustomer.currencyName;
  // 项目编号
  formData.value.fBdkBase = formData.value.fBdkBase;
  formData.value.fBdkBaseName = formData.value.fBdkBaseName;
  formData.value.dcErpOrderItemList.map(item => {
    item.fSettleCurrId = formData.value.dcErpOrderConfigure
      ? formData.value.dcErpOrderConfigure.fSettleCurrId
      : formData.value.fSettleCurrId;
    item.fSettleCurrName = formData.value.dcErpOrderConfigure
      ? formData.value.dcErpOrderConfigure.fSettleCurrName
      : formData.value.fSettleCurrName;
  });
});

// 额外赋值
const handleBillTypeChange = value => {
  const selectedOption = findOptionByDictKey(value);
  if (selectedOption) {
    formData.value.fBillTypeId = value;
    formData.value.fBillTypeDictId = selectedOption.id;
    formData.value.fParentBillTypeDictId = selectedOption.parentId;
  }
};

// 销售组织
const handleSaleOrgChange = value => {
  formData.value.fSaleOrgDictId = value;
  formData.value.realFOrgId = value;
  formData.value.fForeOrgDictId = value;

  const option = findOption(value);
  if (option) {
    formData.value.fSaleOrgId = option.orgCode;
    formData.value.fForeOrgId = option.orgCode;
    formData.value.dcErpOrderItemList.forEach(item => {
      // 结算组织
      item.fPeSettleOrgId = option.orgCode;
      item.fPeSettleOrgDictId = value;
      item.fPeSettleOrgDictName = option.label;
      // 库存组织
      item.fStockOrgId = option.orgCode;
      item.fStockOrgDictId = value;
      item.fStockOrgDictName = option.label;
      // 货主
      item.fOwnerId = option.orgCode;
      item.fOwnerDictId = value;
      item.fOwnerDictName = option.label;
    });
  }
};

// 预测组织
const handleFForeOrgChange = value => {
  formData.value.fSaleOrgDictId = value;
  formData.value.fForeOrgDictId = value;

  // 切换组织清空zhi
  // 切换组织后，清空销售员、TPM、运营跟单、客户、终端客户
  formData.value.fSalerId = null;
  formData.value.fTpm = null;
  formData.value.fOraText3 = null;
  formData.value.fCustId = null;
  formData.value.fOraBase = null;

  const option = findOption(value);
  if (option) {
    formData.value.fForeOrgId = option.orgCode;
    formData.value.dcErpOrderItemList.forEach(item => {
      //预测组织
      item.fSupplyOrgDictId = value;
      item.fSupplyOrgId = option.orgCode;
      // 库存组织
      item.fStockOrgId = option.orgCode;
      item.fStockOrgDictId = value;
      item.fStockOrgDictName = option.label;
      // 供应组织
      item.fSupplyOrgId = option.orgCode;
      item.fSupplyOrgDictId = value;
      item.fSupplyOrgDictName = option.label;
      // 货主
      item.fOwnerDictId = option.orgCode;
      item.fOwnerId = value;
      item.fOwnerDictName = option.label;
    });
  }
};

const handleFStockOrgIdChange = value => {
  formData.value.dcErpOrderItemList[numberIndex.value].fStockOrgDictId = value;
  const option = findOption(value);
  if (option) {
    formData.value.dcErpOrderItemList[numberIndex.value].fStockOrgId = option.orgCode;
  }
};

const findOption = dictKey => {
  for (const option of ORG_LIST_CACHE.value) {
    if (option.id === dictKey) {
      return option;
    }
  }
  return null;
};

const findOptionByDictKey = dictKey => {
  for (const group of groupedOptions.value) {
    for (const option of group.children) {
      if (option.dictKey === dictKey) {
        return option;
      }
    }
  }
  return null;
};

// 分组逻辑：通过 parentId 将数据分组
const groupedOptions = computed(() => {
  return DC_BILL_TYPE.value;
});

// 回显方法
const showData = () => {
  for (const group of groupedOptions.value) {
    for (const option of group.children) {
      if (option.dictKey === formData.value.fBillTypeId) {
        formData.value.fParentBillTypeDictId = option.parentId;
      }
    }
  }

  // 销售员
  SalersOptions.value.push({
    fnumber: formData.value.fSalerId,
    fname: formData.value.fSalerName,
  });

  customerOptions.value.push({
    customerFNumber: formData.value.fCustId,
    customerFName: formData.value.fCustName,
  });

  customerOptions.value.push({
    customerFNumber: formData.value.fOraBase,
    customerFName: formData.value.fOraBaseName,
  });

  currenciesOptinons.value.push({
    currencyCode: formData.value.fSettleCurrId,
    currencyName: formData.value.fSettleCurrName,
  });

  tpmOptions.value.push({
    fnumber: formData.value.fTpm,
    fname: formData.value.fTpmName,
  });

  documentariesOptions.value.push({
    fnumber: formData.value.fOraText3,
    fname: formData.value.fOraText3Name,
  });

  CollectionTermsOptions.value.push({
    fcode: formData.value.fRecConditionId,
    fname: formData.value.fRecConditionIdName,
  });

  projectNumbersOptions.value.push({
    fnumber: formData.value.fBdkBase,
    fname: formData.value.fBdkBaseName,
  });
};

const handleCustomerChange = selectedCustomerId => {
  // 根据选中的 customerFNumber 获取完整的客户数据
  const selectedCustomer = customerOptions.value.find(
    item => item.customerFNumber === selectedCustomerId
  );
  // 汇率 税率
  formData.value.fExchangeRate = formData.value.erpCustomer.exchangeRate;
  formData.value.fOraTaxRate = formData.value.erpCustomer.taxRateName;
  // 币种
  formData.value.fSettleCurrId = formData.value.erpCustomer.currencyCode;
  formData.value.fSettleCurrName = formData.value.erpCustomer.currencyName;
  // 收款条件
  formData.value.fRecConditionId = formData.value.erpCustomer.collectionTermICode;
  formData.value.fRecConditionIdName = formData.value.erpCustomer.collectionTermIName;
};

// 销售员
const handleFSalerChange = selectedCustomerId => {
  const selectedCustomer = SalersOptions.value.find(item => item.fnumber === selectedCustomerId);
  formData.value.fSaleDeptId = selectedCustomer.fdeptCode;
  formData.value.fSaleDeptName = selectedCustomer.fdeptName;
  // 明细销售员要和 上面的 一致
  formData.value.dcErpOrderItemList.forEach(item => {
    item.fBdkBase1 = selectedCustomer.fnumber;
    item.fBdkBase1Name = selectedCustomer.fname;
  });
};

// tpm渲染下面
const handleFTpmChange = selectedCustomerId => {
  const selectedCustomer = tpmOptions.value.find(item => item.fnumber === selectedCustomerId);
  // 明细销售组织是TPM的组织
  formData.value.ftpmDeptId = selectedCustomer.fdeptCode;
  formData.value.ftpmDeptName = selectedCustomer.fdeptName;
  formData.value.dcErpOrderItemList.forEach(item => {
    item.fEwTpm = selectedCustomer.fnumber;
    item.fEwTpmName = selectedCustomer.fname;
  });
};

// 保存数据
const submit = async () => {
  proxy.$refs['ruleFormRef'].validate(async valid => {
    if (valid) {
      loading.value = true;
      try {
        const res = await Api.pdp.dcErporder.submit(formData.value);
        const { code, msg } = res.data;
        if (code == 200) {
          proxy.$message.success(msg);
          const timer = setTimeout(() => {
            router.push('/pdp/execution/list');
            clearTimeout(timer);
          }, 500);
        }
        loading.value = false;
      } catch (error) {
        loading.value = false;
      }
    }
  });
};

// 提交
const passSubmit = async () => {
  if (formData.value.dcErpOrderItemList) {
    let fieldsToCheck;
    if (formData.value.fParentBillTypeDictId == '1870708551385808898') {
      fieldsToCheck = [
        { key: 'fStartDate', label: '预测开始日期' },
        { key: 'fEndDate', label: '预测结束日期' },
        { key: 'fQty', label: '销售数量' },
        { key: 'fAveraType', label: '均化类型' },
        { key: 'fAveraCycle', label: '均化周期' },
        { key: 'fReserveType', label: '预留类型' },
        { key: 'fQlktDate', label: '客户下单日期' },
        { key: 'fEwPhase', label: '阶段' },
        { key: 'fOraText4', label: 'PM回复交期' },
        { key: 'fEwCustomerProduct', label: '客户产品' },
        { key: 'fEwProjectType', label: '项目类型' },
        { key: 'fEwDeviceAttribute', label: '设备属性' },
        { key: 'fOraText5', label: '客户交期ETA' },
      ];
    } else {
      fieldsToCheck = [
        { key: 'fEwFreeReason', label: '免费原因' },
        { key: 'fQty', label: '销售数量' },
        { key: 'fEwProducSeriesId', label: '产品系列' },
        { key: 'fEwPhase', label: '阶段' },
        { key: 'fOraAssistant1', label: '项目名称' },
        { key: 'fPersonLiable', label: '责任人' },
        // { key: 'fEwFreeReason', label: '免费原因' },
        { key: 'fEwCustomerProduct', label: '客户产品' },
        { key: 'fEwProjectType', label: '项目类型' },
        { key: 'fEwDeviceAttribute', label: '设备属性' },
        { key: 'fBdkText3', label: '客户PO' },
        { key: 'fOraText5', label: '客户交期ETA' },
        { key: 'fVersionNo', label: '版本号' },
      ];
    }

    let missingFieldsMessage = '';
    let missingshow = null;

    formData.value.dcErpOrderItemList.forEach((item, index) => {
      const missingFields = fieldsToCheck
        .filter(field => !item[field.key])
        .map(field => field.label);

      if (missingFields.length > 0) {
        missingFieldsMessage += `<span style="color: red;">第 ${
          index + 1
        } 条数据未填写的字段: ${missingFields.join(', ')}</span><br/>`;
        missingshow = true;
      } else {
        missingFieldsMessage += `<span style="color: green;">第 ${
          index + 1
        } 条数据已完整填写</span><br/>`;
        missingshow = false;
      }
    });

    if (missingshow) {
      ElMessageBox.alert(missingFieldsMessage, '表单检查结果', {
        confirmButtonText: '确定',
        dangerouslyUseHTMLString: true,
      });
    } else {
      // 校验通过后，执行提交逻辑
      try {
        await ElMessageBox.confirm('确定通过吗？', '是否通过', {
          cancelButtonText: '取消',
          confirmButtonText: '确定',
          type: 'warning',
        });

        loading.value = true;
        submit(); // 提交接口前的处理
        const res = await Api.pdp.dcErporder.pass(formData.value);
        const { code, msg } = res.data;
        if (code === 200) {
          proxy.$message.success(msg);
        }
      } catch (error) {
        if (error !== 'cancel') {
          proxy.$message.error('提交失败，请稍后重试');
        } else {
          ElMessage({
            type: 'info',
            message: '已取消',
          });
        }
      } finally {
        loading.value = false;
      }
    }
  } else {
    try {
      await ElMessageBox.confirm('确定通过吗？', '是否通过', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning',
      });

      proxy.$refs['ruleFormRef'].validate(async valid => {
        if (valid) {
          loading.value = true;
          submit();
          const res = await Api.pdp.dcErporder.pass(formData.value);
          const { code, msg } = res.data;
          if (code == 200) {
            proxy.$message.success(msg);
          }
        }
      });

      ElMessage({
        type: 'success',
        message: '已通过',
      });
    } catch (error) {
      if (error !== 'cancel') {
        proxy.$message.error('提交失败，请稍后重试');
      } else {
        ElMessage({
          type: 'info',
          message: '已取消',
        });
      }
    } finally {
      loading.value = false;
    }
  }
};

const rejectSubmit = async () => {
  try {
    const rejectValue = await ElMessageBox.prompt('请输入驳回原因', '驳回原因', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    });

    loading.value = true;
    const form = {
      ...formData.value,
      causeOfRejection: rejectValue.value,
    };
    try {
      const res = await Api.pdp.dcErporder.reject(form);
      const { code, msg } = res.data;

      if (code === 200) {
        proxy.$message.success(msg);
        router.push('/pdp/execution/list');
      }
    } catch (error) {
      console.error('API 调用失败:', error);
    } finally {
      loading.value = false;
    }
  } catch {
    // 用户点击“取消”
    ElMessage({
      type: 'info',
      message: '取消驳回',
    });
  }
};
// 获取字典
const dict = async () => {
  loading.value = true;
  try {
    const res = await Api.pdp.dcErporder.dict();
    const { code, data } = res.data;
    if (code == 200) {
      fHeadDeliveryWayType.value = data.交货方式;
      unitType.value = data.计量单位;
      fEwFreeReasonType.value = data.免费原因;
      reservationType.value = data.预留类型;
      costType.value = data.成本类型;
      stageType.value = data.阶段;
      productSeriationType.value = data.客户产品;
      fEwProjectTypeOptions.value = data.项目类型;
      fEwDeviceAttributeOptinos.value = data.设备属性;
      fAveraTypeType.value = data.均化类型;
    }
    loading.value = false;
  } catch (error) {
    loading.value = false;
  }
};

const detail = async id => {
  if (!id) id = route.params.id;
  try {
    loading.value = true;
    const res = await Api.pdp.dcErporder.detail({ id: id });
    const { code, msg, data } = res.data;
    if (code === 200) {
      formData.value = data;
      showData();
      remoteCollectionTermsOptions();
    } else {
      proxy.$message({
        type: 'warning',
        message: msg,
      });
    }
    loading.value = false;
  } catch (err) {
    loading.value = false;
  }
};

// 确认项目名称
const openProjectList = () => {
  ProjectListRef.value.openDialog();
};

/**
 * 结构就是机构
 *
 * */

// 确认项目名称
const confirmProjectList = data => {
  // 项目名称
  formData.value.projectId = data[0].projectId;
  // 销售组织
  formData.value.fSaleOrgDictId = data[0].fSaleOrgDictId;
  formData.value.fSaleOrgId = data[0].fSaleOrgId;
  // 预测组织
  formData.value.fForeOrgDictId = data[0].fSaleOrgDictId;
  formData.value.fForeOrgId = data[0].fSaleOrgId;
  // 销售员
  formData.value.fSalerId = data[0].fSalerId;
  formData.value.fSalerName = data[0].fSalerName;
  // 销售部门
  formData.value.fSaleDeptId = data[0].fSaleDeptId;
  formData.value.fSaleDeptName = data[0].fSaleDeptName;
  // 客户
  formData.value.fCustId = data[0].fCustId;
  formData.value.fCustName = data[0].fCustName;
  // 终端客户
  formData.value.fOraBase = data[0].fOraBase;
  formData.value.fOraBaseName = data[0].fOraBaseName;
  // TPM
  formData.value.fTpm = data[0].fTpm;
  formData.value.fTpmName = data[0].fTpmName;
  // 运营跟单
  formData.value.fOraText3 = data[0].fOraText3;
  formData.value.fOraText3Name = data[0].fOraText3Name;
  // 组织
  formData.value.realFOrgId = data[0].realFOrgId;
  // 结算币种
  formData.value.fSettleCurrId = data[0].fSettleCurrId;
  formData.value.fSettleCurrName = data[0].fSettleCurrName;
  showData();
};

// 远程搜索获取客户列表
const remoteCustomerOptions = async fullname => {
  if (!fullname) return;
  if (fullname.length < 2) return;
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    name: fullname,
  };

  const res = await Api.pdp.erpSelect.customers(form);
  const { code, data } = res.data;
  if (code === 200) {
    customerOptions.value = data;
  }
};

// 远程搜索获取物料编码列表
const remoteMaterialsOptions = async fullname => {
  if (!fullname) return;
  if (fullname.length < 2) return;
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    name: fullname,
  };

  const res = await Api.pdp.erpSelect.materials(form);
  const { code, data } = res.data;
  if (code === 200) {
    materialsOptinons.value = data;
  }
};

// 远程搜索获取物料编码列表
const remoteFMaterialOptions = async fullname => {
  if (!fullname) return;
  if (fullname.length < 5) return;
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    number: fullname,
  };

  const res = await Api.pdp.erpSelect.materials(form);
  const { code, data } = res.data;
  if (code === 200) {
    materialsOptinons.value = data;
  }
};

// 远程搜索获取物料项目名称列表
const remoteProjectNamesOptions = async fullname => {
  if (!fullname) return;
  if (fullname.length < 2) return;
  const form = {
    name: fullname,
    number: fullname,
  };

  const res = await Api.pdp.erpSelect.projectNames(form);
  const { code, data } = res.data;
  if (code === 200) {
    projectNamesOptions.value = data;
  }
};

// 远程搜索获取物料项目编号列表
const remoteProjectNumbersOptions = debounce(async fullname => {
  if (!fullname) return;
  if (fullname.length < 2) return;
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    number: fullname,
    name: fullname,
  };
  const res = await Api.pdp.erpSelect.projectNumbers(form);
  const { code, data } = res.data;
  if (code === 200) {
    projectNumbersOptions.value = data;
  }
}, 500);

// 远程搜索获取物料tpm列表
const remoteTpmOptions = async fullname => {
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    name: fullname,
  };
  const res = await Api.pdp.erpSelect.tpm(form);
  const { code, data } = res.data;
  if (code === 200) {
    tpmOptions.value = data;
  }
};

// 远程搜索获取币种列表
const remoteCurrenciesOptions = async fullname => {
  const form = {
    name: fullname,
  };

  const res = await Api.pdp.erpSelect.currencies(form);
  const { code, data } = res.data;
  if (code === 200) {
    currenciesOptinons.value = data;
  }
};

// 远程搜索获取月结列表
const remoteCollectionTermsOptions = async () => {
  const res = await Api.pdp.erpSelect.collectionTerms();
  const { code, data } = res.data;
  if (code === 200) {
    CollectionTermsOptions.value = data;
  }
};

// 远程搜索获取销售员列表
const remoteSalersOptions = async fullname => {
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    name: fullname,
  };

  const res = await Api.pdp.erpSelect.salers(form);
  const { code, data } = res.data;
  if (code === 200) {
    SalersOptions.value = data;
  }
};

// 远程搜索运营跟单
const remoteDocumentariesOptions = async fullname => {
  const form = {
    orgId: formData.value.fSaleOrgDictId,
    name: fullname,
  };
  const res = await Api.pdp.erpSelect.documentaries(form);
  const { code, data } = res.data;
  if (code === 200) {
    documentariesOptions.value = data;
  }
};

// 远程搜索运营跟单
const remoteProductSeriationOptions = async fullname => {
  const form = {
    name: fullname,
  };
  const res = await Api.pdp.erpSelect.productSeriation(form);
  const { code, data } = res.data;
  if (code === 200) {
    ProductSeriationOptinos.value = data;
  }
};

const handleMaterialChange = row => {
  // 根据选中的编码找到对应的物料名称
  const selectedMaterial = materialsOptinons.value.find(item => item.fname === row.fMaterialName);
  if (selectedMaterial) {
    row.fMaterialId = selectedMaterial.fnumber;
    row.fMaterialName = selectedMaterial.fname;
    row.fMaterialModel = selectedMaterial.fspecification; //更新规格型号
    row.fUnitId = selectedMaterial.funitId;
    row.fUnitName = selectedMaterial.funitName; // //更新单位
  } else {
    row.fMaterialId = ''; // 如果未找到，清空物料编码
    row.fMaterialName = '';
    row.fMaterialModel = ''; // 如果未找到，清空规格型号
    row.fUnitId = '';
    row.fUnitName = ''; //如果未找到，清空单位
  }
};

const handleFMaterialChange = row => {
  // 根据选中的编码找到对应的物料名称
  const selectedMaterial = materialsOptinons.value.find(item => item.fnumber === row.fMaterialId);
  if (selectedMaterial) {
    row.fMaterialId = selectedMaterial.fnumber;
    row.fMaterialName = selectedMaterial.fname;
    row.fMaterialModel = selectedMaterial.fspecification; //更新规格型号
    row.fUnitId = selectedMaterial.funitId;
    row.fUnitName = selectedMaterial.funitName; // //更新单位
  } else {
    row.fMaterialId = ''; // 如果未找到，清空物料编码
    row.fMaterialName = '';
    row.fMaterialModel = ''; // 如果未找到，清空规格型号
    row.fUnitId = '';
    row.fUnitName = ''; //如果未找到，清空单位
  }
};

const handleCtrlC = () => {
  if (!selectedRow.value) {
    proxy.$message.warning('请先选中一行数据进行复制');
    return;
  }
  const row = { ...selectedRow.value, isNew: true };
  const copiedRow = JSON.parse(JSON.stringify(row)); // 深拷贝
  delete copiedRow.id;
  formData.value.dcErpOrderItemList.push(copiedRow);
  // 自动设置为编辑状态
  editRowIndex.value = formData.value.dcErpOrderItemList.length - 1;
  openConfig.value = true;
  originalRowData.value = JSON.parse(JSON.stringify(copiedRow)); // 保存原始数据

  singleSelectTable.value.clearSelection(); // 清空选中状态
  singleSelectTable.value.toggleRowSelection(copiedRow, true); // 设置当前行选中状态
  selectedRow.value = copiedRow; // 更新选中行
};

// 新增行
const handleAdd = async () => {
  if (formData.value.id === undefined || formData.value.id === null || formData.value.id === '') {
    loading.value = true;
    proxy.$refs['ruleFormRef'].validate(async valid => {
      if (valid) {
        try {
          const res = await Api.pdp.dcErporder.submit(formData.value);
          const { code, data, msg } = res.data;
          if (code == 200) {
            proxy.$message.success(msg);
            formData.value = data;
            formData.value.dcErpOrderItemList = [];
            detail(data.id);
            doAddTableLine();
          }
        } catch (error) {
          loading.value = false;
        }
      }
    });
  } else {
    doAddTableLine();
  }
};

// 新增
const doAddTableLine = () => {
  let newRow;
  // 空对象表示一个值
  // 明细 预测单 销售部门是TPM带出来的
  if (formData.value.fParentBillTypeDictId == '1870708551385808898') {
    newRow = {
      isNew: true,
      // 明细TPM
      fEwTpm: formData.value.fTpm,
      // 明细库存组织
      fStockOrgDictId: formData.value.fSaleOrgDictId,
      fStockOrgId: formData.value.fSaleOrgId,
      fStockOrgDictName: formData.value.fSaleOrgDictName,
      // 明细供应组织
      fSupplyOrgDictId: formData.value.fForeOrgDictId,
      fSupplyOrgId: formData.value.fForeOrgId,
      fSupplyOrgDictName: formData.value.fForeOrgDictName,
      // 货主
      fOwnerDictId: formData.value.fSaleOrgDictId,
      fOwnerId: formData.value.fSaleOrgId,
      fOwnerDictName: formData.value.fSaleOrgDictName,
      // 客户
      fCustId: formData.value.fCustId,
      fCustIdName: formData.value.fCustName,
      // 终端客户
      fOraBase4: formData.value.fOraBase,
      fOraBase4Name: formData.value.fOraBaseName,
      // 项目
      fEwProjectType: formData.value.fBdkText7,
      fEwProjectTypeName: formData.value.fBdkText7Name,
      // 订单类型
      fOraCombo: formData.value.fOraCombo,
      // 汇率 税率
      fExchangeRate: formData.value.erpCustomer.exchangeRate,
      fOraTaxRate: formData.value.erpCustomer.taxRateName,
      // 结算币别
      fSettleCurrId: formData.value.fSettleCurrId,
      fSettleCurrIdName: formData.value.fSettleCurrName,
      // 销售员
      fBdkBase1: formData.value.fSalerId,
      fBdkBase1Name: formData.value.fSalerName,
      // 销售部门
      fEwSaleDeptId: formData.value.ftpmDeptId,
      fEwSaleDeptIdName: formData.value.ftpmDeptName,
      // 设备属性
      fEwDeviceAttribute: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwDeviceAttribute
        : null,
      fEwDeviceAttributeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwDeviceAttributeName
        : null,
      // 项目类型
      fEwProjectType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProjectType
        : null,
      fEwProjectTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProjectTypeName
        : null,
      // 客户产品
      fEwCustomerProduct: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCustomerProduct
        : null,
      fEwCustomerProductName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCustomerProductName
        : null,
      // 免费原因
      fEwFreeReason: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwFreeReason
        : null,
      fEwFreeReasonName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwFreeReasonName
        : null,
      // 成本类型
      fEwCostType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCostType
        : null,
      fEwCostTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCostTypeName
        : null,
      // 成本归属专案
      fCostAttrMtoNo: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fCostAttrMtoNo
        : null,
      fCostAttrMtoNoName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fCostAttrMtoNoName
        : null,
      // 项目名称
      fOraAssistant1: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fOraAssistant1
        : null,
      fOraAssistant1Name: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fOraAssistant1Name
        : null,
      // 阶段
      fEwPhase: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwPhase
        : null,
      fEwPhaseName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwPhaseName
        : null,
      // 产品系列
      fEwProducSeriesId: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProducSeriesId
        : null,
      fEwProducSeriesName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProducSeriesName
        : null,
      // 软件工程
      fBdkText12: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText12
        : null,
      // 电子工程
      fBdkText11: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText11
        : null,
      // 电气工程
      fBdkText10: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText10
        : null,
      // 机构工程
      fBdkText9: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText9
        : null,
      // 内部PM
      fBdkText8: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText8
        : null,
      // 结算币种
      fSettleCurrId: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fSettleCurrId
        : null,
      fSettleCurrName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fSettleCurrName
        : null,
      // 均化类型
      fAveraType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fAveraType
        : null,
      fAveraTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fAveraTypeName
        : null,
      // 预留类型
      fReserveType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fReserveType
        : null,
      fReserveTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fReserveTypeName
        : null,
    };
  } else {
    newRow = {
      isNew: true,
      // 明细TPM
      fEwTpm: formData.value.fTpm,
      // 明细库存组织
      fStockOrgDictId: formData.value.fSaleOrgDictId,
      fStockOrgId: formData.value.fSaleOrgId,
      fStockOrgDictName: formData.value.fSaleOrgDictName,
      // 明细结算组织
      fPeSettleOrgDictId: formData.value.fSaleOrgDictId,
      fPeSettleOrgId: formData.value.fSaleOrgId,
      fPeSettleOrgDictName: formData.value.fSaleOrgDictName,
      // 货主
      fOwnerDictId: formData.value.fSaleOrgDictId,
      fOwnerId: formData.value.fSaleOrgId,
      fOwnerDictName: formData.value.fSaleOrgDictName,
      // 明细供应组织
      fSupplyOrgDictId: formData.value.fSaleOrgDictId,
      fSupplyOrgId: formData.value.fSaleOrgId,
      fSupplyOrgDictName: formData.value.fSaleOrgDictName,
      // 客户
      fCustId: formData.value.fCustId,
      fCustName: formData.value.fCustName,
      // 终端客户
      fOraBase4: formData.value.fOraBase,
      fOraBase4Name: formData.value.fOraBaseName,
      // 项目
      fEwProjectType: formData.value.fBdkText7,
      fEwProjectTypeName: formData.value.fBdkText7Name,
      // 设备属性
      fEwDeviceAttribute: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwDeviceAttribute
        : null,
      fEwDeviceAttributeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwDeviceAttributeName
        : null,
      // 项目类型
      fEwProjectType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProjectType
        : null,
      fEwProjectTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProjectTypeName
        : null,
      // 客户产品
      fEwCustomerProduct: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCustomerProduct
        : null,
      fEwCustomerProductName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCustomerProductName
        : null,
      // 免费原因
      fEwFreeReason: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwFreeReason
        : null,
      fEwFreeReasonName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwFreeReasonName
        : null,
      // 成本类型
      fEwCostType: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCostType
        : null,
      fEwCostTypeName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwCostTypeName
        : null,
      // 成本归属专案
      fCostAttrMtoNo: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fCostAttrMtoNo
        : null,
      fCostAttrMtoNoName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fCostAttrMtoNoName
        : null,
      // 项目名称
      fOraAssistant1: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fOraAssistant1
        : null,
      fOraAssistant1Name: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fOraAssistant1Name
        : null,
      // 阶段
      fEwPhase: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwPhase
        : null,
      fEwPhaseName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwPhaseName
        : null,
      // 产品系列
      fEwProducSeriesId: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProducSeriesId
        : null,
      fEwProducSeriesName: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fEwProducSeriesName
        : null,
      // 软件工程
      fBdkText12: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText12
        : null,
      // 电子工程
      fBdkText11: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText11
        : null,
      // 电气工程
      fBdkText10: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText10
        : null,
      // 机构工程
      fBdkText9: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText9
        : null,
      // 内部PM
      fBdkText8: formData.value.dcErpOrderConfigure
        ? formData.value.dcErpOrderConfigure.fBdkText8
        : null,
    };
  }

  // 遍历并检查 isNew 属性
  for (let item of formData.value.dcErpOrderItemList) {
    if (item.isNew === true) {
      proxy.$message.success('请检查是否填写完成');
      return; // 直接结束函数
    }
  }

  formData.value.dcErpOrderItemList.push(newRow);
  numberIndex.value = formData.value.dcErpOrderItemList.length - 1;

  // 自动设置为编辑状态
  editRowIndex.value = formData.value.dcErpOrderItemList.length - 1;
  openConfig.value = true;
  originalRowData.value = JSON.parse(JSON.stringify(newRow)); // 保存原始数据
};

/** 删除按钮操作 */
const handleDelete = () => {
  if (!selectedRow.value?.id) {
    proxy.$message.warning('请先选中一行，进行删除！');
    return;
  }
  const configIds = { ids: selectedRow.value.id };
  proxy
    .$confirm('是否确认删除参数编号为"' + configIds.ids + '"的数据项？')
    .then(async () => {
      return await Api.pdp.erpSelect.delete(configIds);
    })
    .then(() => {
      proxy.$message.success('删除成功');
      detail();
    })
    .catch(() => {});
};

// 双击打开编辑行
const handleRowDbclick = row => {
  proxy.$refs['ruleFormRef'].validate(async valid => {
    if (valid) {
      loading.value = true;
      try {
        const res = await Api.pdp.dcErporder.submit(formData.value);
        const { code, msg } = res.data;
        if (code == 200) {
          proxy.$message.success(msg);
          row.fStockOrgDictId = formData.value.fSaleOrgDictId;
          row.fPeSettleOrgDictId = formData.value.fSaleOrgDictId;
          row.fEwTpm = formData.value.fTpm;
          row.fPeSettleOrgDictName = formData.value.fSaleOrgDictName;

          openConfig.value = true;
          // 获取点击行的索引
          const rowIndex = formData.value.dcErpOrderItemList.indexOf(row);
          editRowIndex.value = rowIndex;
          originalRowData.value = JSON.parse(JSON.stringify(row)); // 保存原始数据
        }
        loading.value = false;
      } catch (error) {
        loading.value = false;
      }
    }
  });
};

const handleRowClick = row => {
  // 获取当前行的下标
  const rowIndex = formData.value.dcErpOrderItemList.findIndex(item => item === row);
  numberIndex.value = rowIndex;
  // 清空之前的选中状态
  if (singleSelectTable.value) {
    singleSelectTable.value.clearSelection();
  }
  // 设置当前行为选中状态
  if (singleSelectTable.value) {
    singleSelectTable.value.toggleRowSelection(row);
  }
};

// 确认编辑
const configSubmit = async (row, rowIndex) => {
  proxy.$refs['ruleTableRef'].validate(async (valid, fields) => {
    if (valid) {
      delete row.isNew;
      const form = {
        ...row,
        dcErpOrderId: formData.value.id,
      };

      const res = await Api.pdp.dcErporder.orderSubmit(form);
      const { code, msg } = res.data;
      if (code === 200) {
        detail(formData.value.id);
        proxy.$message(msg);
        editRowIndex.value = false;
        originalRowData.value = null; // 清空保存的原始数据
      }
    } else {
      // 校验未通过，滚动到验证未通过的地方
      setTimeout(() => {
        const errorDiv = document.getElementsByClassName('is-error');
        if (errorDiv.length > 0) {
          // 先滚动到错误元素
          errorDiv[0].scrollIntoView({
            behavior: 'smooth',
            block: 'center', // 确保对齐到顶部
          });
        }
      }, 0);
      return false;
    }
  });
};

// 取消编辑
const Cancel = (row, rowIndex) => {
  if (row.isNew) {
    // 如果是新增行，直接删除
    formData.value.dcErpOrderItemList.splice(rowIndex, 1);
  } else if (originalRowData.value) {
    // 恢复原始数据
    formData.value.dcErpOrderItemList[rowIndex] = JSON.parse(JSON.stringify(originalRowData.value));
  }

  editRowIndex.value = null; // 退出编辑状态
  originalRowData.value = null; // 清空原始数据
  selectedRow.value = null; // 清空选中行，防止复制操作错误
  singleSelectTable.value.selectRow();
};

// 选中变化事件
const handleSelectionChange = selection => {
  // 保证只有一行被选中，取消多选
  if (selection.length > 1) {
    // 如果多选，清空选中项并只选中最后一行
    singleSelectTable.value.clearSelection();
    const lastSelected = selection[selection.length - 1];
    singleSelectTable.value.toggleRowSelection(lastSelected, true);
    selectedRow.value = lastSelected; // 更新选中行
  } else {
    selectedRow.value = selection[0] || null; // 更新选中行
  }
};
</script>
<style lang="scss">
.business-container {
  .basic-container__card {
    background-color: transparent;

    .el-card__body {
      padding: 0 !important;
    }
  }
}
</style>
<style lang="scss">
.custom-form {
  display: flex;
  flex-wrap: wrap;

  .form-item-info {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
  }

  .form-itme-width_20 {
    width: 20% !important;
    margin-right: 0;

    .form-item-value {
      width: 100%;
      height: 100%;
      border-radius: 4px;
      border: 1px solid #ccc;

      span {
        padding-left: 10px;
      }

      .form-item-placeholder {
        padding-left: 10px;
        color: #a8abb2;
      }
    }

    .form-item-enterprise {
      padding: 9px 12px;
      border: 1px solid #dadbe0;
      font-weight: 400;
      font-size: 14px;
      color: #333;
      line-height: 14px;
      border-radius: 4px;
    }

    .active {
      border: none;
      background: #f78431;
      color: #fff;
    }
  }
}

@media (max-width: 1360px) {
  .custom-form {
    display: flex;
    flex-wrap: wrap;

    .form-item-info {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
    }

    .form-itme-width_20 {
      width: 100% !important;
      margin-right: 0;

      .form-item-value {
        width: 100%;
        height: 100%;
        border-radius: 4px;
        border: 1px solid #ccc;

        span {
          padding-left: 10px;
        }

        .form-item-placeholder {
          padding-left: 10px;
          color: #a8abb2;
        }
      }

      .form-item-enterprise {
        padding: 9px 12px;
        border: 1px solid #dadbe0;
        font-weight: 400;
        font-size: 14px;
        color: #333;
        line-height: 14px;
        border-radius: 4px;
      }

      .active {
        border: none;
        background: #f78431;
        color: #fff;
      }
    }
  }
}
</style>
<style scoped lang="scss">
.wrap-left-form {
  display: flex;
  justify-content: center;
}

.form-center {
  display: flex;
  flex-wrap: wrap;
}

.form-group-header-title {
  margin: 28px 0 20px 0 !important;
}

.form-group-header-btn {
  margin-bottom: 22px;
}

.form-group-title {
  display: flex;
  align-items: center;
  width: 100%;
  margin: 28px 0 32px 0;
  font-weight: 600;
  font-size: 16px;
  color: #333;

  &::before {
    margin-right: 4px;
    display: block;
    content: '';
    width: 4px;
    height: 13px;
    background-color: #f78431;
  }

  .add-box {
    display: flex;
    align-items: center;
    margin-left: 40px;
    font-weight: 400;
    font-size: 14px;
    color: #f78431;
    cursor: pointer;
  }
}

.form-item-row {
  width: 93% !important;
}

.form-item-width {
  width: 100%;
}

.ipt {
  width: 100%;
  border: 0px;
  background: none;
}
.form-display {
  display: flex;
  justify-content: space-around;
  :deep(.el-form-item__label) {
    font-size: 16px;
  }
  :deep(.el-form-item__content) {
    font-size: 16px;
  }
}

.detail-table {
  :deep(td .el-form-item) {
    margin-bottom: 0;
  }
}
</style>
